/*
 * Copyright (c) 悠静<i@mikuhl.cn> 仅用于提交给24年JavaWeb课程所用，侵权必究. 2024-至今. All rights reserved.
 *
 */

package cn.mikuhl.retailmanagementsystem.Controller;

import cn.mikuhl.retailmanagementsystem.Entities.Order;
import cn.mikuhl.retailmanagementsystem.Service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/orders")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping
    public void createOrder(@RequestBody Order order) {
        orderService.insertOrder(order);
    }

    @PutMapping("/{id}")
    public void updateOrder(@PathVariable int id, @RequestBody Order order) {
        order.setId(id);
        orderService.updateOrder(order);
    }

    @GetMapping("/{id}")
    public Order getOrderById(@PathVariable int id) {
        return orderService.getOrderById(id);
    }
}
